package com.yoj.userservice.feign;

import com.yoj.model.entity.User;
import com.yoj.serviceclient.service.user.UserFeignClient;
import com.yoj.userservice.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

/**
 * 用户服务内部接口：仅内部调用接口，不是给前端的
 */
@RestController()
@RequestMapping("/inner")
public class UserClient implements UserFeignClient {

    @Resource
    private UserService userService;

    /**
     * 根据 id 获取用户
     * @param userId 用户 id
     * @return 用户信息
     */
    @GetMapping("/get/id")
    public User getUserById(@RequestParam("userId") long userId) {
        return userService.getById(userId);
    }

    /**
     * 根据 id 列表获取用户列表
     * @param idList 用户 id 列表
     * @return 用户信息列表
     */
    @GetMapping("/get/ids")
    public List<User> listUserByIds(@RequestParam("idList") Collection<Long> idList) {
        return userService.listByIds(idList);
    }

}
